Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabular UI for naming linked files #12624

Draft
wants to merge 52 commits into
base: main
Choose a base branch
from

Conversation

priyanshu16095
Copy link
Contributor

@priyanshu16095 priyanshu16095 commented Mar 5, 2025

Closes #11368

This PR adds a tabular construct similar to "Key patterns" for "Linked files name" in the Linked files tab in preferences.

Mandatory checks

  • I own the copyright of the code submitted and I licence it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

Screenshot (202)

Sorry, something went wrong.

@priyanshu16095 priyanshu16095 changed the title Tabular UI Tabular UI for naming linked files Mar 5, 2025
@priyanshu16095 priyanshu16095 marked this pull request as ready for review March 21, 2025 02:29
Comment on lines +44 to +48
if ((initialNamePattern.getDefaultValue() == null) || initialNamePattern.getDefaultValue().equals(Pattern.NULL_PATTERN)) {
defaultPattern = "";
} else {
defaultPattern = initialNamePattern.getDefaultValue().stringRepresentation();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code violates the fail-fast principle by nesting logic inside else branch. Should check for valid state first and return/assign early.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is OK in this context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment OK? or the code?

@Override
public void setValues() {
viewModel.setValues();
BibEntryTypesManager entryTypesManager = Injector.instantiateModelOrService(BibEntryTypesManager.class);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct instantiation through Injector in method body violates separation of concerns. The dependency should be injected through constructor or setter method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Maybe you can add an argument BibEntryTypesManager to the constructor of LinkedFilesTab?

@@ -48,7 +48,7 @@ public static Optional<MetaDataDiff> compare(MetaData originalMetaData, MetaData
return Optional.empty();
} else {
MetaDataDiff diff = new MetaDataDiff(originalMetaData, newMetaData);
List<Difference> differences = diff.getDifferences(new GlobalCitationKeyPatterns(CitationKeyPattern.NULL_CITATION_KEY_PATTERN));
List<Difference> differences = diff.getDifferences(new GlobalCitationKeyPatterns(Pattern.NULL_PATTERN));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same GlobalCitationKeyPatterns object is created twice in the class - in compare() and toString(). This violates DRY principle and creates redundant object allocations.

@@ -14,12 +14,12 @@
*/
public abstract class AbstractCitationKeyPatterns {

protected CitationKeyPattern defaultPattern = CitationKeyPattern.NULL_CITATION_KEY_PATTERN;
protected Pattern defaultPattern = Pattern.NULL_PATTERN;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public methods should not return null values. Consider using Optional instead of allowing null patterns, even for internal representation.

Comment on lines +82 to +83
public static List<Pattern> getAllPatterns() {
return Arrays.stream(Pattern.class.getDeclaredFields())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method lacks JavaDoc despite being a complex public method that uses reflection and handles exceptions. Documentation would help explain its purpose and behavior.

}

/**
* Gets an object for a desired key from this LinkedFileNamePattern or one of it's parents (in the case of
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaDoc contains grammatical error ('it's' should be 'its') and references Hashtable in description while code uses HashMap, making documentation misleading.

}

public static GlobalLinkedFileNamePatterns fromPattern(String pattern) {
return new GlobalLinkedFileNamePatterns(new Pattern(pattern));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing validation for the pattern parameter before creating new Pattern object. Input parameters should be validated to fail fast.

Comment on lines +569 to +571
if (preferenceFileNamePattern != null) {
mainPrefsNode.put(JabRefCliPreferences.LINKED_FILE_NAME_PATTERNS_NODE, "[auth_year]");
if (prefs.hasKey(JabRefCliPreferences.IMPORT_FILENAMEPATTERN)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code violates the fail-fast principle by nesting logic inside conditional blocks instead of returning early. The nested if condition should be restructured.

@@ -68,6 +68,7 @@ public static void runMigrations(JabRefGuiPreferences preferences) {
upgradeCleanups(preferences);
moveApiKeysToKeyring(preferences);
removeCommentsFromCustomEditorTabs(preferences);
upgradeFileImportPatternToLinkedFileNamePattern(preferences, mainPrefsNode);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method lacks proper JavaDoc documentation explaining the migration process, parameters, and potential side effects, which is important for complex migration operations.

@priyanshu16095
Copy link
Contributor Author

To remove code duplication ,
Renamed LinkedFileNamePattern and CitationKeyPattern to Pattern
Renamed LinkedFileNamePatternsPanelItemModel and CitationKeyPatternsItemModel to PatternsItemModel
Renamed LinkedFileNamePatternsSuggestionCell and CitationKeyPatternsSuggestionCell to PatternsSuggestionCell

The thing I am not sure about is whether the preference migration is correct or not.

<TextField fx:id="fileDirectoryPattern" GridPane.columnIndex="1" GridPane.rowIndex="1"
prefWidth="300" minWidth="300" maxWidth="300"/>
</GridPane>
<Label text="%( Note: Press return to commit changes in the table! )"/>
Copy link
Member

@InAnYan InAnYan Mar 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to remove parenthesis (to ease translation).

And change text style to italics

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used this because it is similarly used in the citation key pattern naming table.

Screenshot (265)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To maintain a consistent UI across JabRef, I used it here. Should I change it?

new GlobalLinkedFileNamePatterns(filePreferences.fileNamePatternProperty().get().getDefaultValue());
patternListProperty.forEach(item -> {
String patternString = item.getPattern();
if (!"default".equals(item.getEntryType().getName())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic value?

Or IntelliJ IDEA hint to prevent operations on null values?

private final StringProperty fileDirectoryPatternProperty = new SimpleStringProperty();
private final BooleanProperty confirmLinkedFileDeleteProperty = new SimpleBooleanProperty();
private final BooleanProperty moveToTrashProperty = new SimpleBooleanProperty();

private final ListProperty<PatternsItemModel> patternListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
private final ObjectProperty<PatternsItemModel> defaultNamePatternProperty = new SimpleObjectProperty<>(
new PatternsItemModel(new LinkedFileNamePatternsPanelViewModel.DefaultEntryType(), ""));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw you used empty strings ("") in some places.

Does it differ somewhat from Pattern.NULL_PATTERN?

@priyanshu16095 priyanshu16095 marked this pull request as draft March 26, 2025 13:37
@@ -103,8 +102,8 @@ public MetaData parse(Map<String, String> data, Character keywordSeparator) thro
* @return the given metaData instance (which is modified, too)
*/
public MetaData parse(MetaData metaData, Map<String, String> data, Character keywordSeparator) throws ParseException {
CitationKeyPattern defaultCiteKeyPattern = CitationKeyPattern.NULL_CITATION_KEY_PATTERN;
Map<EntryType, CitationKeyPattern> nonDefaultCiteKeyPatterns = new HashMap<>();
Pattern defaultCiteKeyPattern = org.jabref.logic.citationkeypattern.Pattern.NULL_PATTERN;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactoring from CitationKeyPattern to Pattern should be accompanied by updated tests to ensure the new implementation behaves as expected.

@jabref-machine
Copy link
Collaborator

JUnit tests are failing. In the area "Some checks were not successful", locate "Tests / Unit tests (pull_request)" and click on "Details". This brings you to the test output.

You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide.

@jabref-machine
Copy link
Collaborator

Note that your PR will not be reviewed/accepted until you have gone through the mandatory checks in the description and marked each of them them exactly in the format of [x] (done), [ ] (not done yet) or [/] (not applicable).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: changes required Pull requests that are not yet complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Citation key generator and Linked files
5 participants